<!--
* @description 
* @fileName userReal.vue
* @author huangyu
* @date 2023/03/08 10:28:18
!-->
<template>
   <div class="app-container">
      <van-nav-bar title="预申请账号审核" />
      <van-swipe-cell v-for="(item,index) in list" :key="index">
         <van-cell :title="`${item.gameName} [${item.gameCode}]`" :value="item.status">
            <div>审核通过</div>
         </van-cell>
         <template #right>
            <div v-if="item.state==0">
               <van-button square type="primary" text="通过" @click="clickUpdate(item,1)" />
               <van-button square type="danger" text="拒绝" @click="submitUpdate(item,-1)"  />
            </div>
            <div v-else>
               <van-button square type="info" text="非待审核" />
            </div>
         </template>
      </van-swipe-cell>
      <van-pagination v-model="pageindex" :total-items="total" :items-per-page="pagesize" @change="changePage" />
   </div>
</template>

<script>
import { get } from '@/common/app.js'
import { Toast } from 'vant';
export default {
   components: {},
   data() {
       return {
         token: this.$store.state.token,
         list: [],
         pageindex: 1,
         pagesize: 20,
         total: 0,
         id: "",
       }
   },
   mounted() {
      this.getData()
   },
   methods: {
      changePage(value){
         this.pageIndex = value
         this.getData()
      },
      getData(){
         if(this.token){
            let params = {
               type: 'getUser',
               api: 'api-user-real-list',
               data: {
                  pageIndex: this.pageindex,
                  pageSize: this.pagesize,
               },
            }
            get('game', params).then(res => {
               if (res) {
                  this.list = res.list
                  this.total = res.total
               }
            })
         }
      },
      clickUpdate(row,value){
         this.id = row._id
         this.register(row,value)
      },
      register(row,value){
            // row.password = md5('123456')
            row.gameId = 1
            row.isSecrecy = false
            row.powerInfo = {
                powerMenu: [],
                roleInfo: [], //角色管理 查看和管理权限
                levelInfo: [], //等级，会员等级
                functionInfo: [], //功能,寄售数量限制，收购数量限制
            }
            let params = {
                type: 'getLogin',
                api: 'api-register',
                data: row,
            }
            get('game', params).then(res => {
                if (res) {
                    if(res.type=='error'){
                     Toast.fail(res.msg)
                        return
                    }
                    if(res.id){
                        // 注册功能更新状态
                        this.submitUpdate(row,value)
                    }
                }
            })
        },
      submitUpdate(row,value){
            let params = {
                type: 'getUser',
                api: 'api-user-real-update',
                data: {
                    _id: row._id,
                    status: value,
                },
            }
            get('game', params).then(res => {
                if (res) {
                    if(value==1){
                     Toast.success("审核，注册成功！")
                    }else{
                     Toast.success("审核拒绝！")
                    }
                    this.getData()
                }
            })
        },
   },
}
</script>

<style scoped>

</style>